﻿using System.Text;
using ComHlp.enums;

namespace ComHlp.Classes
{
    /// <summary> internal static class for saving several things... </summary>
    public static class ComStatics
    {
        /// <summary> encoder for cp850/utf8 NOT for ebcdic </summary>
        public static Encoding Encoder { private set; get; }

        public static bool UseUtf8 { private set; get; }

        public static bool SafeUtf8 { private set; get; } 

        private static ushort TerminalNumber { set; get; }

        public static string TerminalNumberFormatted => TerminalNumber.ToString("D3");


        public static void SetConnectionData(ItxCodepage codePage, ushort terminalNumber, bool safeUtf8)
        {
            TerminalNumber = terminalNumber;
            switch (codePage)
            {
                case ItxCodepage.Cp850:
                    Encoder = Encoding.GetEncoding(850);
                    break;
                case ItxCodepage.Cp936:
                    Encoder = Encoding.GetEncoding(936);
                    break;
                case ItxCodepage.Utf8:
                    UseUtf8 = true;
                    SafeUtf8 = safeUtf8;
                    Encoder = Encoding.UTF8;
                    break;
            }
        }
    }
}
